<?php
defined('SEJUJOPEFDNGJSL') or exit('Access denied');
class member {
	var $db;
	var $user_name;
	var $userid;

	public function __construct(){
		global $db;
		$this->db = &$db;
	}

	//获取user_info表中的信息
	public function getum($user_name='',$str='*'){
		$condition=$user_name?"uname='$user_name'":"uname='$this->user_name'";
		
		$this->db->query("select $str from ld_user_info where $condition",2);
		
		return $this->db->rs;
	}
	//根据用户名获取user_account表中的信息
	public function getuv($user_name='',$str='*'){
		$condition=$user_name?"uname='$user_name'":"uname='$this->user_name'";
		$this->db->query("select $str from ld_user_account where $condition",2);
		return $this->db->rs;
	}
	//根据id获取user_account表中的信息
	public function getuv1($userid='',$str='*'){
		$condition=$userid?"id='$userid'":"id='$this->userid'";
		$this->db->query("select $str from ld_user_account where $condition",2);
		return $this->db->rs;
	}


	public function getuvinfo($userid='',$str='*'){
		$condition=$userid?"id=$userid":"id=$this->userid";
		$this->db->query("select $str from ld_user_account where $condition",2);
		return $this->db->rs;
	}
	//取得管理员和权限
	public function getua($user_name='',$str='*'){
		$condition=$user_name?"a.uname='$user_name'":"a.uname='$this->user_name'";
		$this->db->query("select $str from ld_user a,ld_privilege o where a.role=o.edid and $condition",2);
		return $this->db->rs;
	}
	//如果第二个参数为真则通过用户账号查，否则通过用户id查
	public function getuserinfo($s,$c=''){
		$condition=$c?"v.uname='$s'":"v.id=$s";
		//var_dump($condition);
		//exit();
		$this->db->query("select * from ld_user_account v,ld_user_info m where v.id=m.id and $condition ",2);
		
		return $this->db->rs;
	}

	public function getusername($s){
		if(empty($s)) return '';

		$this->db->query("select real_name from ld_user_info where id=$s",2);
		
		if(empty($this->db->rs)){
			return '';
		}else{
			return $this->db->rs['real_name'];
		}
	}


	public function getuserid($s){
		if(empty($s)) return '';

		$this->db->query("select uname from ld_user_info where id=$s",2);
		if(empty($this->db->rs)){
			return '';
		}else{
			return $this->db->rs['uname'];
		}
	}


	public function getusid($s){
		if(empty($s)) return '';

		$this->db->query("select id from ld_user_info where uname='$s'",2);
		if(empty($this->db->rs)){
			return '';
		}else{
			return $this->db->rs['id'];
		}
	}


	public function getreguser($s){
		if(empty($s)) return '';
		$a=explode('|',$s);
		$this->db->query("select uname from ld_user_info where id=".$a[0],2);
		if(empty($this->db->rs)){
			return '';
		}else{
			return $this->db->rs['uname'].' '.($a[1]?'<span style=\'color:#f00\'>后台</span>':'');
		}
	}

	//是否存在上线
	public function upperuser_exists($s){
		$this->db->query("select id from ld_user_account where id in(0".$s."0) and is_passed=0 limit 1",2);
		if(empty($this->db->rs)){
			return false;
		}else{
			return true;
		}	
	}


	//下级未开通的会员sunli
	public function downtu_exists($s){
		$this->db->query("select id from ld_user_account where parents_ids like '%,$s,%' and is_passed=0 limit 1",2);
		if(empty($this->db->rs)){
			return false;
		}else{
			return true;
		}
	}

	public function user_exists($s){
		$this->db->query("select id,parents_ids,uname,leader_number from ld_user_account where uname='$s'",2);
		return $this->db->rs;
	}
	
	//推荐人是否存在
	public function tu_exists($s){
		$this->db->query("select id,parents_ids,leader_number from ld_user_account where is_passed>0 and uname='$s'",2);
		return $this->db->rs;
	}	
		
	//邮箱是否已使用
	public function email_exists($s){
		$this->db->query("select id from ld_user_info where rgemail='$s'",2);
		if(empty($this->db->rs)){
			return false;
		}else{
			return true;
		}
	}		
	//身份证是否已使用
	public function card_exists($s){
		$this->db->query("select id from ld_user_info where rgcard='$s'",2);
		if(empty($this->db->rs)){
			return false;
		}else{
			return true;
		}
	}	
	//手机号是否已使用
	public function mobile_exists($s){
		$this->db->query("select id from ld_user_info where phone='$s'",2);
		if(empty($this->db->rs)){
			return false;
		}else{
			return true;
		}
	}
	//手机号和用户名是否对应
	public function user_mobile_match($uname,$mobiles){
		$this->db->query("select id from ld_user_info where phone='$mobiles' and uname = '$uname'",2);
		if(empty($this->db->rs)){
			return false;
		}else{
			return true;
		}
	}
	
	//提供帮助数/未完成
	public function getcunkuan($s){
		$this->db->query("select count(id) a from ld_give_help where uid=$s",2);
		if(empty($this->db->rs["a"])){
			$arr[0]=0;
		}else{
			$arr[0]=$this->db->rs["a"];
		}

		$this->db->query("select count(id) a from ld_give_help where `status`=0 and uid=$s",2);
		if(empty($this->db->rs["a"])){
			$arr[1]=0;
		}else{
			$arr[1]='<span style="color:#f00">'.$this->db->rs["a"]."</span>";
		}		
		return $arr[0]."/".$arr[1];
	}
	//获得帮助数/未完成
	public function getqukuan($s){
		$this->db->query("select count(id) a from ld_get_help where get_help_uid=$s",2);
		if(empty($this->db->rs["a"])){
			$arr[0]=0;
		}else{
			$arr[0]=$this->db->rs["a"];
		}

		$this->db->query("select count(id) a from ld_get_help where `status`=0 and get_help_uid=$s",2);
		if(empty($this->db->rs["a"])){
			$arr[1]=0;
		}else{
			$arr[1]='<span style="color:#f00">'.$this->db->rs["a"]."</span>";
		}		
		return $arr[0]."/".$arr[1];
	}
	//取得获得帮助人的用户名
	public function getgqname($s){
		if(empty($s)) return '';

		$this->db->query("select get_help_uid from ld_get_help where id=$s",3);

		if(empty($this->db->fval)){
			return '';
		}else{
			$this->db->query("select uname from ld_user_info where id=".$this->db->fval,3);
			if(empty($this->db->fval)){
				return '';
			}else{
				return $this->db->fval;
			}
		}
	}	

	//取得提供帮助人的用户名
	public function getgpname($s){
		if(empty($s)) return '';

		$this->db->query("select uid from ld_give_help where id=$s",3);

		if(empty($this->db->fval)){
			return '';
		}else{
			$this->db->query("select uname from ld_user_info where id=".$this->db->fval,3);
			if(empty($this->db->fval)){
				return '';
			}else{
				return $this->db->fval;
			}
		}
	}
	//取得获得帮助人的昵称
	public function getenname($s){
		if(empty($s)) return '';

		$this->db->query("select get_help_uid from ld_get_help where id=$s",3);

		if(empty($this->db->fval)){
			return '';
		}else{
			$this->db->query("select nick_name from ld_user_info where id=".$this->db->fval,3);
			if(empty($this->db->fval)){
				return '';
			}else{
				return $this->db->fval;
			}
		}
	}	

	//取得提供帮助人的昵称
	public function getinname($s){
		if(empty($s)) return '';

		$this->db->query("select uid from ld_give_help where id=$s",3);

		if(empty($this->db->fval)){
			return '';
		}else{
			$this->db->query("select nick_name from ld_user_info where id=".$this->db->fval,3);
			if(empty($this->db->fval)){
				return '';
			}else{
				return $this->db->fval;
			}
		}
	}
	//取得提供帮助的用户的介绍人（上线）
	public function getldpname($s){
		if(empty($s)) return '';

		$this->db->query("select uid from ld_give_help where id=$s",3);

		if(empty($this->db->fval)){
			return array();
		}else{

			$this->db->query("select * from ld_user_info where id=(select introducer_id from ld_user_account where id=".$this->db->fval.")",2);
			if(empty($this->db->rs)){
				return array();
			}else{
				return $this->db->rs;
			}
		}
	}		
	//获取获得帮助的用户的介绍人（上线）
	public function getldqname($s){
		if(empty($s)) return '';

		$this->db->query("select get_help_uid from ld_get_help where id=$s",3);

		if(empty($this->db->fval)){
			return array();
		}else{

			$this->db->query("select * from ld_user_info where id=(select introducer_id from ld_user_account where id=".$this->db->fval.")",2);
			if(empty($this->db->rs)){
				return array();
			}else{
				return $this->db->rs;
			}
		}
	}
	public function get_bank($bankno){
		$this->db->query("select * from ld_bank where bankno='".$bankno."'",2);
		return $this->db->rs['bankno'];
	}
}
?>